import java.util.HashMap;
import java.util.Map;

/**
 * 选课系统管理类：处理核心业务逻辑
 */
public class CourseSelectionSystem {
    // 存储实体的容器（Map通过ID快速查询）
    private Map<String, Course> courses = new HashMap<>();
    private Map<String, Teacher> teachers = new HashMap<>();
    private Map<String, Student> students = new HashMap<>();

    // 添加课程
    public void addCourse(Course course) {
        courses.put(course.getCourseId(), course);
    }

    // 添加教师
    public void addTeacher(Teacher teacher) {
        teachers.put(teacher.id, teacher);  // 访问父类protected属性id（同包/子类可访问）
    }

    // 添加学生
    public void addStudent(Student student) {
        students.put(student.id, student);  // 访问父类protected属性id
    }

    // 教师开课（关联教师与课程）
    public void teacherOpenCourse(String teacherId, String courseId) {
        Teacher teacher = teachers.get(teacherId);
        Course course = courses.get(courseId);
        if (teacher != null && course != null) {
            teacher.setCourseId(courseId);  // 调用Teacher的public方法
            course.setTeacherId(teacherId); // 调用Course的public方法
            System.out.println(teacher.name + " 成功开设课程：" + course.getCourseName());
            // 访问Teacher的protected属性name（同包/子类可访问）
        } else {
            System.out.println("教师或课程不存在，开课失败");
        }
    }

    // 打印学生详细课表
    public void printStudentDetailSchedule(String studentId) {
        Student student = students.get(studentId);
        if (student != null) {
            System.out.println("=== " + student.name + " 的详细课表 ===");  // 访问protected属性name
            for (String courseId : student.getCourseIds()) {  // 调用Student的public Getter（访问private属性）
                Course course = courses.get(courseId);
                if (course != null) {
                    Teacher teacher = teachers.get(course.getTeacherId());
                    System.out.println("课程名称：" + course.getCourseName() +
                            "，地点：" + course.getLocation() +
                            "，时间：" + course.getTime() +
                            "，教师：" + (teacher != null ? teacher.name : "未知"));
                }
            }
            System.out.println("=============\n");
        } else {
            System.out.println("学生不存在");
        }
    }
}